/**
 * Handle user login and logout
 */
package cult.ticketing.processor;

import cult.ticketing.bean.Member;
import cult.ticketing.dao.MemberDAO;

/**
 * @author 51158282
 *
 */
public class AuthenticationProcessor {
    private final String NON_MEMBER = "non_member";
    private final String INCORRECT_PWD = "incorrect_pwd";
    private final String ALREADY_LOGGEDIN = "already_loggedin";
    private NotificationProcessor notice;

    /**
     *
     */
    public AuthenticationProcessor() {
            // TODO Auto-generated constructor stub
    }

    /**
     * Check user login info
     * @param email
     * @param pwd
     * @return a string indicating login result.
     */
    public String login(String email, String pwd) {
            String loginResult = null;
            MemberDAO memberDAO = new MemberDAO();
            Member member = memberDAO.getMemberByEmail(email);

            if (member.equals(null))
                loginResult = NON_MEMBER;
            else if (!member.getPwd().equals(pwd))
                loginResult = INCORRECT_PWD;
            else {
                if (member.getLoginStatus() == true)
                    loginResult = ALREADY_LOGGEDIN;
                else
                    loginResult = member.getRole();
            }

            return loginResult;
    }

    public void logout(int memberId) {
           // Member member = Member.getMemberById(memberId);
          //  member.setLoginStatus(false);
    }
}
